<template>
  <div>
    <el-row style="margin-bottom: 30px">
    <el-clo :span="3">
      <button style="border:none;background-color: white;" @click="ShowWarehouseData">＜返回</button>
    </el-clo>
   <el-col :span="0.1">
    <span>|</span>
   </el-col>
    <el-clo :span="1">
      <button style="border:none;background-color: white;"><b>仓库编辑</b></button>
    </el-clo>
  </el-row>
  <el-form
    ref="ruleFormRef"
    style="max-width: 1300px;margin-left: 50px;"
    label-width="auto"
    class="demo-ruleForm"
    status-icon
  >
    <el-form-item label="仓库编码" prop="name">
      <el-input v-model="form.WarehousNumBer" />
    </el-form-item>
    <el-form-item label="仓库名称" prop="name">
      <el-input v-model="form.WarehouseName" />
    </el-form-item>
    <el-form-item label="仓库地址" prop="name">
      <el-input v-model="form.WarehouseAddr" />
    </el-form-item>
    <el-form-item label="备注" prop="desc">
      <el-input v-model="form.WarehouseRemark" type="textarea" />
    </el-form-item>
    <el-form-item label="状态" prop="region">
      <el-select v-model="form.WarehouseState" placeholder="请选择状态">
        <el-option label="有效" :value=false />
        <el-option label="无效" :value=true />
      </el-select>
    </el-form-item>
  </el-form>
  <button style="margin-left: 1250px;background-color: #526ada;font-size: 15px;border-radius:4px ;border-color: #526ada ;height: 35px;width: 90px;" @click="InsertWarehouse">确定<img src="../Warehouse/img/image.png" alt="button img" style="width: 18px;height: 15px;"></button>
  </div>
</template>
<script lang="ts" setup>
import {reactive} from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';
const apiUri=import.meta.env.VITE_APP_API_URL_WAREHOUSE;
const router=useRouter();
const Data=localStorage.getItem("userInfo");
console.log('用户信息',Data);
//const UserData=JSON.parse(Data);
const form=reactive({
WarehouseId:0,
WarehousNumBer :'',
WarehouseName :'',
WarehouseAddr:'',
WarehouseRemark:'',
WarehouseState :'',
WarehouseIsDel :false,
Handle :'张三',
HandleContext :'添加仓库',
Pid:1,
IsDelete :false
})

const UserLogData=reactive({
UserLogId :0,
Handle :'张三',
HandleContext:'添加仓库', 
Pid :1,
IsDelete:false
})
 
const InsertWarehouse=()=>{
  //获取当前时间
  const DatetimeNow=new Date();
  console.log("123");
  axios.post(apiUri+"/api/Warehouse/AddWarehouseData",{
    WarehouseId:form.WarehouseId,
    WarehousNumBer :form.WarehousNumBer,
    WarehouseName :form.WarehouseName,
    WarehouseAddr:form.WarehouseAddr,
    WarehouseRemark:form.WarehouseRemark,
    WarehouseState :form.WarehouseState,
    WarehouseIsDel :form.WarehouseIsDel,
    Handle :form.Handle,
    HandleContext :form.HandleContext,
    HandleTime :DatetimeNow,
    Pid:form.Pid,
    IsDelete :form.IsDelete
  }).then(res=>{
    console.log(res.data.code)
    if(res.data.code>0)
    {
      AddUserLogData();
    }
    else
    {
      ElMessage.error('添加失败');
    }
  })
}

//跳转仓库显示表
const ShowWarehouseData=()=>{
  router.push('/ShowWarehouse');
}

//添加日志
const AddUserLogData=()=>{
  axios.post(apiUri+"/api/UserLog/AddUserLogData",{
  UserLogId :UserLogData.UserLogId,
  Handle :UserLogData.Handle,
  HandleContext:UserLogData.HandleContext,
  Pid :UserLogData.Pid,
  IsDelete:UserLogData.IsDelete
  }).then(res=>{
    if(res.data.code>0)
    {
      ElMessage.success('添加成功');
    }
    else
    {
      ElMessage.error('添加失败');
    }
  })
}

</script>